<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	 <meta charset="utf-8">
	 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	 <title th:replace="common/base::pagetitle"></title>
	 <link th:replace="common/base::static"/>
	 <link rel='stylesheet' th:href="@{/static/css/element.ui.2.13.2.index.css}">
</head>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
	 
	 <div class="layui-row wlb-fluid-padding15">
		  
		  <div class="layui-col-md12">
				
				<div class="layui-card">
					 <!--					 <div class="layui-card-header">流程图</div>-->
					 <!--					 1 ——> 2 ——> 3 ——> 4-->
					 <div class="layui-card-body">
						  <div class="layui-form" lay-filter="">
								<!-- 渲染json schema模板 -->
								<table id="templateTable" lay-data="{id: 'id'}" lay-filter="templateTable"></table>
								<div class="layui-form-item layui-hide">
									 <!--									 <input type="button" lay-submit="" lay-filter="kFormCheck" id="kFormCheck" value="验证凭证">-->
									 <input type="text" id="bankId" name="bankId" th:value="${bankId}" placeholder="保存ID" autocomplete="off" class="layui-input">
								</div>
						  </div>
					 </div>
				</div>
		  
		  </div>
	 </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>

<script type="text/html" id="deptTpl">
	 {{#  if(d.bankId == null || d.bankId == ''){ }}
	 	<span class="layui-badge layui-bg-blue">平台方</span>
	 {{#  } else { }}
		  {{# var data = wlbKit.get(api.sys.getDept + d.bankId).data; }}
		  {{# return data ? data.name : '<span class="layui-badge-rim">未分配</span>'; }}
	 {{# } }}
	
</script>
<script type="text/html" id="templateTypeTpl">
	 {{#  if(d.templateType == 0){ }}
	 <span class="layui-badge layui-bg-green">平台模板</span>
	 {{#  } else { }}
	 <span class="layui-badge layui-bg-green">用户模板</span>
	 {{# } }}
</script>

<!--头部工具栏模板-->
<script type="text/html" id="headToolbarTpl">
	 <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
	 <button class="layui-btn layui-btn-sm" lay-event="batchdel">删除</button>
</script>

<script type="text/javascript" th:inline="javascript">
	 var ttable;
    layui.use(['form', 'table'], function () {
        var $ = layui.$, form = layui.form, table = layui.table;
        ttable = table;
        //核心机构id
        var compId = wlbKit.getUrlParam("compId");
        
        //加载模板验收数据模板
        table.render($.extend(config.layui.table, {
            elem: '#templateTable'
            , url: BASE_WEB + 'voucher/generate/choice/getTemplate?compId='+compId //数据接口
            , cols: [[ //表头
                {type: 'radio', fixed: 'left'}
                , {field: 'id', title: '模板ID', hide: true, width: 100}
                , {field: 'name', title: '模板名称', width: 150}
                , {field: 'bankId', title: '所属机构', sort: true, templet: '#deptTpl'}
                , {field: 'templateType', title: '模板类型', width: 120, templet: '#templateTypeTpl'}
                , {field: 'description', title: '描述', width: 250}
            ]]
            , done: function(res, curr, count){      //禁止选中
                if ($("#bankId").val() != null && ''!=$("#bankId").val()) {
                    layui.each(res.data, function(i, item){
                        if(item.bankId == $("#bankId").val()){
                            //选中银行
                            $(".layui-table-view[lay-id='templateTable'] .layui-table-body tr[data-index= '"+i+"' ] .layui-form-radio").click();
                        }else{
                            $(".layui-table tr[data-index="+i+"] input[type='radio']").prop('disabled',true);
                            //禁止选中样式
                            $(".layui-table tr[data-index="+i+"] input[type='radio']").next().addClass('layui-btn-disabled');
                            //设置背景颜色
                            $(".layui-table tr[data-index="+i+"]").css("background-color", "#EEEED1").find('td').prop('disabled',true)
								}
                    });
					 }
            }
        }));

       
    })
    function getCheck(){
        //获取表格选中数据
        var checkStatus = ttable.checkStatus('templateTable');
        //交给父页面去校验
        // if (checkStatus.data.length <= 0) {
        //     wlbKit.errorMsg("请选择至少选择一条验收数据");
        //     return false;
        // }
		  var templateObj = {};
        $(checkStatus.data).each(function (i, o) {//o即为表格中一行的数据
            templateObj.id = o.id;//模板id
            templateObj.bankId = o.bankId;//银行id，选择平台模板时，该字段为null
        });
        console.log("222" + JSON.stringify(templateObj));
        return templateObj;
    }
</script>

</body>
</html>